package com.ruicar.afs.cloud.channel.applyuser.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruicar.afs.cloud.channel.affiliation.service.ChannelBaseInfoTempService;
import com.ruicar.afs.cloud.channel.applyuser.conditiion.ApplyUserCondition;
import com.ruicar.afs.cloud.channel.applyuser.conditiion.ApplyUserDTO;
import com.ruicar.afs.cloud.channel.applyuser.conditiion.SendApplyAdminDTO;
import com.ruicar.afs.cloud.channel.applyuser.entity.ApplyUser;
import com.ruicar.afs.cloud.channel.applyuser.service.ApplyUserService;
import com.ruicar.afs.cloud.channel.applyuser.vo.ApplyUserVO;
import com.ruicar.afs.cloud.channel.applyuserrole.entity.ApplyUserRole;
import com.ruicar.afs.cloud.channel.applyuserrole.service.ApplyUserRoleService;
import com.ruicar.afs.cloud.channel.applyuserroletemp.entity.ApplyUserRoleTemp;
import com.ruicar.afs.cloud.channel.applyuserroletemp.service.ApplyUserRoleTempService;
import com.ruicar.afs.cloud.channel.channelworkflow.entity.WorkTaskAssign;
import com.ruicar.afs.cloud.channel.channelworkflow.entity.WorkTaskCreated;
import com.ruicar.afs.cloud.channel.channelworkflow.entity.WorkTaskDetail;
import com.ruicar.afs.cloud.channel.channelworkflow.service.WorkTaskAssignService;
import com.ruicar.afs.cloud.channel.channelworkflow.service.WorkTaskCreatedService;
import com.ruicar.afs.cloud.channel.channelworkflow.service.WorkTaskDetailService;
import com.ruicar.afs.cloud.channel.common.enums.ChannelAfsFlowEnum;
import com.ruicar.afs.cloud.channel.common.mq.sender.config.ArchiveConfig;
import com.ruicar.afs.cloud.channel.common.mq.sender.impl.SenderChannelToArchiveImpl;
import com.ruicar.afs.cloud.channel.common.until.ChannelConfig;
import com.ruicar.afs.cloud.channel.online.condition.ChannelOnlineCondition;
import com.ruicar.afs.cloud.channel.online.entity.ChannelBaseInfoTemp;
import com.ruicar.afs.cloud.channel.online.feign.ApplyFeignService;
import com.ruicar.afs.cloud.channel.register.condition.SubmitDTO;
import com.ruicar.afs.cloud.channel.witness.utils.WitnessDic;
import com.ruicar.afs.cloud.common.core.constant.CommonConstants;
import com.ruicar.afs.cloud.common.core.enums.AfsEnumUtil;
import com.ruicar.afs.cloud.common.core.exception.AfsBaseException;
import com.ruicar.afs.cloud.common.core.log.annotation.SysLog;
import com.ruicar.afs.cloud.common.core.security.util.SecurityUtils;
import com.ruicar.afs.cloud.common.core.uid.UidGenerator;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.common.modules.apply.enums.CarTypeEnum;
import com.ruicar.afs.cloud.image.entity.ComAttachmentFile;
import com.ruicar.afs.cloud.image.service.ComAttachmentFileService;
import com.ruicar.afs.cloud.workflow.api.dto.flowprocess.WorkFlowResponse;
import com.ruicar.afs.cloud.workflow.api.dto.flowprocess.request.QueryFLowCmdRequest;
import com.ruicar.afs.cloud.workflow.api.dto.flowprocess.request.StartFlowRequest;
import com.ruicar.afs.cloud.workflow.api.dto.flowprocess.request.TaskSubmitRequest;
import com.ruicar.afs.cloud.workflow.api.dto.flowprocess.response.FlowCmdBean;
import com.ruicar.afs.cloud.workflow.gwt.service.WorkflowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.*;

import static com.ruicar.afs.cloud.channel.online.untils.ChannelOnlineConstants.BUSINESS_TYPE_NEW_CAR;
import static com.ruicar.afs.cloud.channel.online.untils.ChannelOnlineConstants.BUSINESS_TYPE_OLD_CAR;

/**
 * @author Ice
 * @date 2020/9/7 18:31
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/applyUser")
@Api(value = "apply_user", description = "进件用户申请表")
public class ApplyUserController {

    private final ApplyUserService applyUserService;
    private final ApplyUserRoleService applyUserRoleService;
    private final ApplyUserRoleTempService applyUserRoleTempService;

    private final ChannelBaseInfoTempService channelBaseInfoTempService;
    private final UidGenerator uidGenerator;
    private final WorkflowService workflowService;
    private final WorkTaskDetailService workTaskDetailService;
    private ChannelConfig channelConfig;
    private final ApplyFeignService applyFeignService;

    private final WorkTaskAssignService workTaskAssignService;
    private final WorkTaskCreatedService workTaskCreatedService;
    private final ComAttachmentFileService comAttachmentFileService;
    private final SenderChannelToArchiveImpl senderChannelToArchiveImpl;

    @Transactional
    @PostMapping("/addApplyUser")
    @ApiOperation(value = "添加进件端传递过来的申请")
    public IResponse<Boolean> upStatus(@RequestBody ApplyUserCondition condition) throws JsonProcessingException {
        if(condition.getNewUser()==null&&condition.getOldUser()==null){
            throw  new AfsBaseException("申请审核失败！");
        }

        // 去存储影像信息
        if(condition.getNewUser()!=null){
            ChannelBaseInfoTemp baseInfoTemp=channelBaseInfoTempService.getById(condition.getNewUser().getChannelId());
            condition.getNewUser().setFileType(condition.getComAttachementFile().getFileType());
            condition.getNewUser().setFileId(condition.getComAttachementFile().getFileId());
            applyUserService.save(condition.getNewUser());
           this.foundWorkFlow(condition.getNewUser().getUsername(),condition.getNewUser().getBusinessType(),condition.getNewUser().getChannelId());
            // 发起工作流
        }
        if(condition.getOldUser()!=null){
            condition.getOldUser().setFileType(condition.getComAttachementFile().getFileType());
            condition.getOldUser().setFileId(condition.getComAttachementFile().getFileId());
            applyUserService.save(condition.getOldUser());
              this.foundWorkFlow(condition.getOldUser().getUsername(),condition.getOldUser().getBusinessType(),condition.getOldUser().getChannelId());
        }
        if(condition.getSysUserRole()!=null&&condition.getSysUserRole().size()>0){

            applyUserRoleService.saveBatch(condition.getSysUserRole());
        }
        if(condition.getSysUserRoleTemp()!=null&&condition.getSysUserRoleTemp().size()>0){
            applyUserRoleTempService.saveBatch(condition.getSysUserRoleTemp());
        }

        // 发起工作流

        return new IResponse<Boolean>().setMsg("申请成功");
    }

    public  void foundWorkFlow(String name,String type,Long channelId) throws JsonProcessingException {
        ApplyUser temp =applyUserService.getOne(Wrappers.<ApplyUser>query().lambda().eq(ApplyUser::getUsername,name).eq(ApplyUser::getBusinessType,type));
        // 查询合作商信息
        ChannelBaseInfoTemp baseInfo= channelBaseInfoTempService.getById(channelId);
        StartFlowRequest startFlowNew = new StartFlowRequest();
        startFlowNew.setAfsFlowKey(AfsEnumUtil.key(ChannelAfsFlowEnum.APPLY_USER));
        startFlowNew.setBizDataId(uidGenerator.getUID()+"");
        startFlowNew.setFlowName(AfsEnumUtil.desc(ChannelAfsFlowEnum.APPLY_USER));
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(temp);
        JSONObject cancelJson = JSONObject.parseObject(json);
        // 判断业务类型
        if(CarTypeEnum.newCar.toString().equals(temp.getBusinessType())){
            //业务类型:新车
            cancelJson.put(AfsEnumUtil.key(ChannelAfsFlowEnum.BUSINESS_TYPE),BUSINESS_TYPE_NEW_CAR);
        }else if(CarTypeEnum.oldCar.toString().equals(temp.getBusinessType())){
            //业务类型:二手车
            cancelJson.put(AfsEnumUtil.key(ChannelAfsFlowEnum.BUSINESS_TYPE),BUSINESS_TYPE_OLD_CAR);
        }else {
            throw new AfsBaseException("获取业务类型失败！");
        }
        // 判断渠道归属
        if(baseInfo.getChannelBelong()==""||baseInfo.getChannelBelong()==null){
            throw new AfsBaseException("获取渠道归属失败！");
        }else {
            cancelJson.put(AfsEnumUtil.key(ChannelAfsFlowEnum.CHANNEL_BELONG),baseInfo.getChannelBelong());
        }
        workflowService.startWorkFlow(startFlowNew,cancelJson);


        //保存业务相关数据、用户前端逻辑判断
        WorkTaskDetail detail = new WorkTaskDetail();
        detail.setBizDataId(startFlowNew.getBizDataId());
        detail.setName(baseInfo.getChannelFullName());
        detail.setFlowName(AfsEnumUtil.desc(ChannelAfsFlowEnum.APPLY_USER));
        // 判断业务类型
        if(CarTypeEnum.newCar.toString().equals(temp.getBusinessType())){
            //业务类型:新车
            detail.setBusinessType(BUSINESS_TYPE_NEW_CAR);
        }else if(CarTypeEnum.oldCar.toString().equals(temp.getBusinessType())){
            //业务类型:二手车
            detail.setBusinessType(BUSINESS_TYPE_OLD_CAR);
        }else {
            throw new AfsBaseException("获取业务类型失败！");
        }

        //挂牌车id绑定
        detail.setBusinessKey(temp.getId());
        workTaskDetailService.save(detail);

        // 给挂牌车数据绑定工作流实例id
        temp.setBizDataId(startFlowNew.getBizDataId());
        applyUserService.update(temp,Wrappers.<ApplyUser>query().lambda().eq(ApplyUser::getUsername,name).eq(ApplyUser::getBusinessType,type));
    }

    @PostMapping("/getApplyUser")
    @ApiOperation(value = "分页查询见证人数据列表")
    public IResponse<IPage<ApplyUserVO>> getChannelWitnessListData(@RequestBody ApplyUserDTO user) {
        // 先获取登陆人的角色
        List<String> roles =SecurityUtils.getRoles();
        if(roles.size()<=0){
            throw new AfsBaseException("此用户暂无权限查询！");
        }
        Page page = new Page(user.getPageNumber(), user.getPageSize());
        IPage<List<ApplyUserVO>> list= applyUserService.getApplyUser(page,roles,AfsEnumUtil.key(ChannelAfsFlowEnum.APPLY_USER),user);
//        IPage<ApplyUser> list = applyUserService.page(new Page(user.getPageNumber(), user.getPageSize())
//                , Wrappers.<ApplyUser>query().lambda()
//                        .eq(ApplyUser::getDelFlag, "0"));
        return IResponse.success(list);
    }

    @PostMapping("/getNewRole")
    @ApiOperation(value = "获取进件新车角色")
    public IResponse getNewRole() {
        Map<String, String> requestHeader = new HashMap<>();
        requestHeader.put("clientId", channelConfig.getApplyAdminClientId());
        requestHeader.put("clientSecret", channelConfig.getApplyAdminClientSecret());
        return applyFeignService.getApplyRoleByType(CarTypeEnum.newCar.toString(),requestHeader) ;
    }

    @PostMapping("/getOldRole")
    @ApiOperation(value = "获取进件二手车角色")
    public IResponse getOldRole() {
        Map<String, String> requestHeader = new HashMap<>();
        requestHeader.put("clientId", channelConfig.getApplyAdminClientId());
        requestHeader.put("clientSecret", channelConfig.getApplyAdminClientSecret());
        return applyFeignService.getApplyRoleByType(CarTypeEnum.oldCar.toString(),requestHeader) ;
    }


    @PostMapping("/getUserById")
    @ApiOperation(value = "通过id 获取信息")
    public IResponse getUserById(@RequestBody ApplyUser user) {
        ApplyUser us =applyUserService.getById(user.getId());
        if(us==null){
            throw  new AfsBaseException("用户已被审核！");
        }
        return IResponse.success(us);
    }
    @PostMapping("/getUserRole")
    @ApiOperation(value = "通过用户信息获取用户角色信息")
    public IResponse getUserRole(@RequestBody ApplyUser user) {
        List<ApplyUserRoleTemp> userRoles=applyUserRoleTempService.list(Wrappers.<ApplyUserRoleTemp>query().lambda().eq(ApplyUserRoleTemp::getUserId,user.getUserId()).eq(ApplyUserRoleTemp::getBusinessType,user.getBusinessType()));
        List<Long> ids =new ArrayList<>();
        if(userRoles.size()>0){
            for (ApplyUserRoleTemp role: userRoles){
                ids.add(role.getRoleId());
            }
        }
        return IResponse.success(ids);
    }

    @PostMapping("/getFormerUserRole")
    @ApiOperation(value = "通过用户信息获取曾经用户角色信息")
    public IResponse getFormerUserRole(@RequestBody ApplyUser user) {

        List<ApplyUserRole> userRoles=applyUserRoleService.list(Wrappers.<ApplyUserRole>query().lambda().eq(ApplyUserRole::getUserId,user.getUserId()).eq(ApplyUserRole::getBusinessType,user.getBusinessType()));
        List<Long> ids =new ArrayList<>();
        if(userRoles.size()>0){
            for (ApplyUserRole role: userRoles){
                ids.add(role.getRoleId());
            }
        }
        return IResponse.success(ids);
    }

    @PostMapping("/toExamine")
    @ApiOperation(value = "获取进件二手车角色")
    @Transactional
    public IResponse toExamine(@RequestBody ApplyUserDTO user) throws JsonProcessingException {
        ApplyUser applyUser =applyUserService.getById(user);
        List<ApplyUserRole> applyUserRoleList =applyUserRoleService.list(Wrappers.<ApplyUserRole>query().lambda().eq(ApplyUserRole::getUserId,applyUser.getUserId().toString()).eq(ApplyUserRole::getBusinessType,applyUser.getBusinessType()));
        user.setApplyUserRoleList(applyUserRoleList);

        List<ApplyUserRoleTemp> applyUserRoleTempList =applyUserRoleTempService.list(Wrappers.<ApplyUserRoleTemp>query().lambda().eq(ApplyUserRoleTemp::getUserId,applyUser.getUserId().toString()).eq(ApplyUserRoleTemp::getBusinessType,applyUser.getBusinessType()));
        user.setApplyUserRoleTempList(applyUserRoleTempList);
        if(applyUser==null){
            throw  new AfsBaseException("用户已被审核！");
        }
        List<ApplyUser> userList=applyUserService.list(Wrappers.<ApplyUser>query().lambda().eq(ApplyUser::getUserId,applyUser.getUserId()));
        if(userList.size()>1){
            // 这边计算下我同意的这一个包含没有同意的那一个的数据嘛
            if(CarTypeEnum.newCar.toString().equals(applyUser.getBusinessType())){
                // 说明是新车
                List<ApplyUserRoleTemp> list=applyUserRoleTempService.list(Wrappers.<ApplyUserRoleTemp>query().lambda().eq(ApplyUserRoleTemp::getUserId,applyUser.getUserId()).eq(ApplyUserRoleTemp::getBusinessType,applyUser.getBusinessType()));
                List<Long> ids =new ArrayList<>();
                for(ApplyUserRoleTemp role:list){
                    ids.add(role.getRoleId());
                }
                List<ApplyUserRoleTemp> list2=applyUserRoleTempService.list(Wrappers.<ApplyUserRoleTemp>query().lambda().eq(ApplyUserRoleTemp::getUserId,applyUser.getUserId()).eq(ApplyUserRoleTemp::getBusinessType, CarTypeEnum.oldCar.toString()));
                List<Long> ids2 =new ArrayList<>();
                for(ApplyUserRoleTemp role:list2){
                    ids2.add(role.getRoleId());
                }

                if(ids.containsAll(ids2)){
                    applyUser.setSign(CommonConstants.STATUS_ERROR);
                }

            }else {
                List<ApplyUserRoleTemp> list=applyUserRoleTempService.list(Wrappers.<ApplyUserRoleTemp>query().lambda().eq(ApplyUserRoleTemp::getUserId,applyUser.getUserId()).eq(ApplyUserRoleTemp::getBusinessType,applyUser.getBusinessType()));
                List<Long> ids =new ArrayList<>();
                for(ApplyUserRoleTemp role:list){
                    ids.add(role.getRoleId());
                }
                List<ApplyUserRoleTemp> list2=applyUserRoleTempService.list(Wrappers.<ApplyUserRoleTemp>query().lambda().eq(ApplyUserRoleTemp::getUserId,applyUser.getUserId()).eq(ApplyUserRoleTemp::getBusinessType, CarTypeEnum.newCar.toString()));
                List<Long> ids2 =new ArrayList<>();
                for(ApplyUserRoleTemp role:list2){
                    ids2.add(role.getRoleId());
                }

                if(ids.containsAll(ids2)){
                    applyUser.setSign(CommonConstants.STATUS_ERROR);
                }
            }

        }

        if (WitnessDic.STATUS_PASS.equals(user.getStatus())) {

            if(CommonConstants.STATUS_ERROR.equals(applyUser.getSign())){
                List<ApplyUser> list=applyUserService.list(Wrappers.<ApplyUser>query().lambda().eq(ApplyUser::getUserId,applyUser.getUserId()));
                if(list.size()>0){
                    for(ApplyUser u:list){
                        // 如果是通过
                        SubmitDTO dto =new SubmitDTO();
                        dto.setRegisterId(u.getId());
                        dto.setApprove("1");
                        dto.setBizDataId(u.getBizDataId());
                        submit(dto);
                    }
                }
            }else {
                // 如果是通过
                SubmitDTO dto =new SubmitDTO();
                dto.setRegisterId(applyUser.getId());
                dto.setApprove("1");
                dto.setBizDataId(applyUser.getBizDataId());
                submit(dto);
            }


        }else if(WitnessDic.STATUS_REFUSE.equals(user.getStatus())){
            // 这边进来是退回
            if(CommonConstants.STATUS_ERROR.equals(applyUser.getSign())){
                List<ApplyUser> list=applyUserService.list(Wrappers.<ApplyUser>query().lambda().eq(ApplyUser::getUserId,applyUser.getUserId()));
                if(list.size()>0){
                    for(ApplyUser u:list){
                        // 如果是回退
                        SubmitDTO dto =new SubmitDTO();
                        dto.setRegisterId(u.getId());
                        dto.setApprove("3");
                        dto.setBizDataId(u.getBizDataId());
                        submit(dto);
                    }
                }
            }else {
                // 如果是退回
                SubmitDTO dto =new SubmitDTO();
                dto.setRegisterId(applyUser.getId());
                dto.setApprove("3");
                dto.setBizDataId(applyUser.getBizDataId());
                submit(dto);
            }


        }
        if(CommonConstants.STATUS_ERROR.equals(applyUser.getSign())){
            // 删除关系表数据
            applyUserRoleService.remove(Wrappers.<ApplyUserRole>query().lambda().eq(ApplyUserRole::getUserId,applyUser.getUserId()));
            applyUserRoleTempService.remove(Wrappers.<ApplyUserRoleTemp>query().lambda().eq(ApplyUserRoleTemp::getUserId,applyUser.getUserId()));
            // 说明同意任何一个另一个默认同意
            applyUserService.remove(Wrappers.<ApplyUser>query().lambda().eq(ApplyUser::getUserId,applyUser.getUserId()));
            comAttachmentFileService.remove(Wrappers.<ComAttachmentFile>query().lambda().eq(ComAttachmentFile::getBusiNo,applyUser.getUserId().toString()));
        }else {
            if(userList.size()==1){
                applyUserService.remove(Wrappers.<ApplyUser>query().lambda().eq(ApplyUser::getUserId,applyUser.getUserId()));
                applyUserRoleService.remove(Wrappers.<ApplyUserRole>query().lambda().eq(ApplyUserRole::getUserId,applyUser.getUserId()));
                applyUserRoleTempService.remove(Wrappers.<ApplyUserRoleTemp>query().lambda().eq(ApplyUserRoleTemp::getUserId,applyUser.getUserId()));
                comAttachmentFileService.remove(Wrappers.<ComAttachmentFile>query().lambda().eq(ComAttachmentFile::getBusiNo,applyUser.getUserId().toString()));
            }else {
                applyUserRoleService.remove(Wrappers.<ApplyUserRole>query().lambda().eq(ApplyUserRole::getUserId,applyUser.getUserId()).eq(ApplyUserRole::getBusinessType,applyUser.getBusinessType()));
                applyUserRoleTempService.remove(Wrappers.<ApplyUserRoleTemp>query().lambda().eq(ApplyUserRoleTemp::getUserId,applyUser.getUserId()).eq(ApplyUserRoleTemp::getBusinessType,applyUser.getBusinessType()));
                // 单一操作
                applyUserService.remove(Wrappers.<ApplyUser>query().lambda().eq(ApplyUser::getId,applyUser.getId()));
            }
        }
        // 发送到进件端进行处理
        SendApplyAdminDTO dto = new SendApplyAdminDTO();
        dto.setBusinessType(applyUser.getBusinessType());
        dto.setStatus(user.getStatus());
        dto.setUserId(applyUser.getUserId());
        dto.setReason(user.getReason());
        dto.setSign(applyUser.getSign());
        dto.setApplyUserRoleTempList(user.getApplyUserRoleTempList());
        dto.setApplyUserRoleList(user.getApplyUserRoleList());
        dto.setDeptId(applyUser.getDeptId());
        dto.setFormerDeptId(applyUser.getFormerDeptId());
        dto.setUserRealName(applyUser.getUserRealName());
        dto.setFormerUserRealName(applyUser.getFormerUserRealName());
        dto.setPhone(applyUser.getPhone());
        dto.setFormerPhone(applyUser.getFormerPhone());
        dto.setUserEmail(applyUser.getUserEmail());
        dto.setFormerUserEmail(applyUser.getFormerUserEmail());


        Map<String, String> requestHeader = new HashMap<>();
        requestHeader.put("clientId", channelConfig.getApplyAdminClientId());
        requestHeader.put("clientSecret", channelConfig.getApplyAdminClientSecret());
        IResponse rr= applyFeignService.toExamineUser(dto,requestHeader) ;
        if(!CommonConstants.SUCCESS.equals(rr.getCode())){
            throw new AfsBaseException(rr.getMsg());
        }
        return IResponse.success(Boolean.TRUE).setMsg("操作成功！");
    }
    //  审核发起工作流
    public void submit(SubmitDTO dto) throws JsonProcessingException {
        WorkTaskAssign assgin = workTaskAssignService.getOne(Wrappers.<WorkTaskAssign>query().lambda().eq(WorkTaskAssign::getBizDataId, dto.getBizDataId()));
        WorkTaskCreated created = workTaskCreatedService.getOne(Wrappers.<WorkTaskCreated>query().lambda().eq(WorkTaskCreated::getBizDataId, dto.getBizDataId()));
        WorkTaskDetail detail = workTaskDetailService.getOne(Wrappers.<WorkTaskDetail>query().lambda().eq(WorkTaskDetail::getBizDataId, dto.getBizDataId()));
        //提交完成之后删除其他人员代办
        List<WorkTaskAssign> assignList = workTaskAssignService.list(Wrappers.<WorkTaskAssign>query().lambda().eq(WorkTaskAssign::getBizDataId, dto.getBizDataId()));

        TaskSubmitRequest taskSubmitRequest = new TaskSubmitRequest();
        taskSubmitRequest.setGwtUserId(assgin.getAssignId());
        taskSubmitRequest.setAfsFlowKey(created.getAfsFlowKey());
        taskSubmitRequest.setBizDataId(created.getBizDataId());
        QueryFLowCmdRequest request = new QueryFLowCmdRequest();
        request.setFlowInstanceId(created.getFlowInstanceId());
        WorkFlowResponse<List<FlowCmdBean>> cmdResponse = workflowService.queryFlowCmd(request);
        List<FlowCmdBean> cmdList = cmdResponse.getAfsData();
        FlowCmdBean cmd = workTaskCreatedService.channelApprove(dto.getApprove(),cmdList);

        ApplyUser  temp =applyUserService.getById(dto.getRegisterId());
        if(cmd!=null){
            taskSubmitRequest.setCmdId(cmd.getId());
            ObjectMapper mapper = new ObjectMapper();
            //获取配置节点信息
            String json = mapper.writeValueAsString(temp);
            JSONObject cancelJson = JSONObject.parseObject(json);
            workflowService.taskSubmit(taskSubmitRequest,cancelJson);

            //删除剩余节点数据信息
            for(int i=0;i<assignList.size();i++){
                workTaskAssignService.removeById(assignList.get(i).getId().toString());
            }
        }else {
            throw new AfsBaseException("提交工作流失败！");
        }
    }

    @RequestMapping(value = "/sendApplyUser", method = RequestMethod.POST)
    @ApiOperation(value = "贷后归档用户信息mq消息推送")
    @SysLog("贷后归档用户信息mq消息推送")
    @Transactional(rollbackFor = Exception.class)
    public IResponse sendApplyUser(@RequestBody ApplyUserVO vo) {
        log.info("==================================归档用户信息mq消息推送开始==================================》");
        senderChannelToArchiveImpl.archivePushMQ(vo.getUserId().toString(), ArchiveConfig.wworguser);
        log.info("==================================归档用户信息mq消息推送结束==================================》");
        return IResponse.success("推送成功");
    }

}
